/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

FIVe3D
Flash Interactive Vector-based 3D
Mathieu Badimon  |  five3d@mathieu-badimon.com

http://five3D.mathieu-badimon.com  |  http://five3d.mathieu-badimon.com/archives/  |  http://code.google.com/p/five3d/

/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import net.badimon.five3D.display.DisplayObjectContainer;
import net.badimon.five3D.display.Scene;
import net.badimon.five3D.geom.Angle;
import net.badimon.five3D.geom.Matrix;
import net.badimon.five3D.geom.Point;

class net.badimon.five3D.display.DisplayObject {

	private var __scene:Scene;
	public var _clip:MovieClip;
	public var _parent:DisplayObjectContainer;
	private var __visible:Boolean = true;
	private var __x:Number = 0;
	private var __y:Number = 0;
	private var __z:Number = 0;
	private var __scalex:Number = 100;
	private var __scaley:Number = 100;
	private var __scalez:Number = 100;
	private var __rotationx:Number = 0;
	private var __rotationy:Number = 0;
	private var __rotationz:Number = 0;
	private var __matrix:Matrix;
	public var __concatenatedmatrix:Matrix;
	private var __render:Boolean = true;

	function DisplayObject(scene:Scene, parentclip:MovieClip, name:String, depth:Number, parent:DisplayObjectContainer) {
		__scene = scene;
		_clip = parentclip.createEmptyMovieClip(name, depth);
		_parent = parent;
		__matrix = new Matrix();
	}

	public function get _name():String {
		return _clip._name;
	}

	public function getDepth(Void):Number {
		return _clip.getDepth();
	}

	public function getNextHighestDepth(Void):Number {
		return _clip.getNextHighestDepth();
	}

	public function swapDepths(target:Object):Void {
		if (isNaN(target)) _clip.swapDepths(target._clip);
		else _clip.swapDepths(target);
	}

	public function get _alpha():Number {
		return _clip._alpha;
	}

	public function set _alpha(value:Number):Void {
		_clip._alpha = value;
	}

	public function get _visible():Boolean {
		return __visible;
	}

	public function set _visible(value:Boolean):Void {
		__visible = value;
		__scene.__render = true;
		askRendering();
	}

	public function setMask(displayobject:DisplayObject):Void {
		_clip.setMask(displayobject._clip);
	}

	public function get _xmouse():Number {
		return __concatenatedmatrix.getInverseCoordinates(__scene.__clip._xmouse, __scene.__clip._ymouse, __scene._viewdistance).x;
	}

	public function get _ymouse():Number {
		return __concatenatedmatrix.getInverseCoordinates(__scene.__clip._xmouse, __scene.__clip._ymouse, __scene._viewdistance).y;
	}

	public function get _xymouse():Point {
		return __concatenatedmatrix.getInverseCoordinates(__scene.__clip._xmouse, __scene.__clip._ymouse, __scene._viewdistance);
	}

	public function get _x():Number {
		return __x;
	}

	public function set _x(value:Number):Void {
		__x = value;
		__scene.__render = true;
		askRendering();
	}

	public function get _y():Number {
		return __y;
	}

	public function set _y(value:Number):Void {
		__y = value;
		__scene.__render = true;
		askRendering();
	}

	public function get _z():Number {
		return __z;
	}

	public function set _z(value:Number):Void {
		__z = value;
		__scene.__render = true;
		askRendering();
	}

	public function get _scalex():Number {
		return __scalex;
	}

	public function set _scalex(value:Number):Void {
		__scalex = value;
		__scene.__render = true;
		askRendering();
	}

	public function get _scaley():Number {
		return __scaley;
	}

	public function set _scaley(value:Number):Void {
		__scaley = value;
		__scene.__render = true;
		askRendering();
	}

	public function get _scalez():Number {
		return __scalez;
	}

	public function set _scalez(value:Number):Void {
		__scalez = value;
		__scene.__render = true;
		askRendering();
	}

	public function get _rotationx():Number {
		return __rotationx;
	}

	public function set _rotationx(value:Number):Void {
		__rotationx = Angle.formatRotation(value);
		__scene.__render = true;
		askRendering();
	}

	public function get _rotationy():Number {
		return __rotationy;
	}

	public function set _rotationy(value:Number):Void {
		__rotationy = Angle.formatRotation(value);
		__scene.__render = true;
		askRendering();
	}

	public function get _rotationz():Number {
		return __rotationz;
	}

	public function set _rotationz(value:Number):Void {
		__rotationz = Angle.formatRotation(value);
		__scene.__render = true;
		askRendering();
	}

	public function askRendering(Void):Void {
		__render = true;
	}

	public function get onEnterFrame():Function {
		return _clip.onEnterFrame;
	}

	public function set onEnterFrame(func:Function):Void {
		initializeEvent("onEnterFrame", func);
	}

	private function initializeEvent(name:String, func:Function):Void {
		if (func == undefined) {
			delete _clip[name];
		} else {
			var ref:DisplayObject = this;
			_clip[name] = function():Void {
				func.call(ref);
			};
		}
	}
}